<!--
 * @Author: jlzm
 * @Date: 2020-03-02 10:49:55
 * @LastEditors: jlzm
 * @LastEditTime: 2020-06-18 16:28:07
 * @FilePath: \MPShop\mixins\afterSale\refunds.vue
--> 
<script>
import { mapState, mapMutations } from "vuex";

import { cancelRefunds } from "@/lib/api/refundsServer/info";
export default {
	data() {
		return {
			/* 物流状态数据 */
			logisticsStatusData:[
				{
					name:"快递收件(揽件)",
					value:"0"
				},
				{
					name:"在途中",
					value:"1"
				},
				{
					name:"正在派件",
					value:"2"
				},
				{
					name:"已签收",
					value:"3"
				},
				{
					name:"派送失败",
					value:"4"
				},
				{
					name:"疑难件",
					value:"5"
				},
				{
					name:"退件签收",
					value:"6"
				}
			]
		};
	},
	computed: {
		...mapState("afterSale", ["applicationRefundsData"])
	},
	methods: {
		...mapMutations("afterSale", ["saveApplicationRefundsData"]),
		// 再次申请
		applyAgain(item) {
			//   this.applicationRefundsData.applied = false;
			//   this.applicationRefundsData.refundsId = item.refundsId;
			//   this.applicationRefundsData.orderId = item.orderId;
			//   const refundsList = [];
			//   for (const goods of item.refundGoodsList) {
			//     refundsList.push({
			//       orderGoodsId: goods.orderGoodsId,
			//       refundsNumber: goods.refundsNumber
			//     });
			//   }
			//   console.log("refundsList", refundsList);
			//   this.applicationRefundsData.list = refundsList;
			//   this.saveApplicationRefundsData(this.applicationRefundsData);
			//   uni.navigateTo({
			//     url: "/pages/user/pages/afterSale/refundsType"
			//   });
		},

		// 撤销申请
		async cancelRefunds(id) {
			const showModalData = {
				title: "撤销申请",
				content: "确认撤销退款申请吗？",
				showCancel: true
			};
			await this.$api.showModal(showModalData);
			await this.updateRefundApply(id);
		},

		updateRefundApply(refundsId) {
			const propsData = {
				refundsId
			};
			return cancelRefunds(propsData).then(res => {
				this.$api.showToast(res.resultInfo || "撤销成功");
			});
		},

		// 查看物流
		seeLogistics(singleNumber) {
			uni.navigateTo({
				url: `/pages/user/pages/logistics/logistics?singleNumber=${singleNumber}`
			});
		},

		/**
		 * 操作按钮展示
		 * @param { Number } btnType // 类型 1: 撤销申请; 2: 填写物流; 3: 再次申请; 4: 查看物流
		 * @param { Number } status  // 0买家撤销, 100买家申请, 200买家待发货, 300买家已发货, 400: 退款完成, 500: 商家拒绝, 600微信拒绝
		 */
		viewBtn(status, btnType) {
			let isView = false;
			switch (btnType) {
				case 1:
					if (status === 100 || status === 200) {
						isView = true;
					}
					break;

				case 2:
					if (status === 200) {
						isView = true;
					}
					break;
				case 3:
					if (status === 0 || status === 500) {
						isView = true;
					}
					break;
				case 4:
					if (status === 300 || status === 400) {
						isView = true;
					}
					break;

				default:
					break;
			}
			return isView;
		}
	}
};
</script>
